#pragma once
#include "../Gui.h"

enum PowerStatusType
{
	POW_CRITICAL,         /// The battery power in critical state,the system will auto suspend
	POW_VLOW,             /// The battery power is  <= 20%
	POW_LOW,			   /// The battery power is  <= 40%
	POW_NORMAL,           /// The battery power is  <= 60%
	POW_HIGH,             /// The battery power is  <= 80
	POW_VHIGH,            /// The battery power is  <= 100%
	POW_CHARGING,         ///  Charging state
	POW_CHARGEFULL,       ///  Charging full
	POW_UNKNOWN,          /// Unknown system power state
};

#ifdef UNDER_CE
#include "Pm.h"

class GUI_API CPowerThread
{
public:
    CPowerThread(void);
    ~CPowerThread(void);

public:
    BOOL ResumnSign();      //Not support now
    void GetCallbackFunction(void (* *pCallbackFunc)(PowerStatusType powStatus, int iBatteryPercent));
    void SetCallbackFunction(void (*pCallbackFunc)(PowerStatusType powStatus, int iBatteryPercent));
    void StopCapture();
    BOOL StartCapture();
    BOOL GetRunStatus();
    void SetTimeout(ULONG ulTime);


protected:
    virtual void OnNotifyPower(PowerStatusType powStatus, int iBatteryPercent);


    //The critical section function
    inline void		InitLock()    { InitializeCriticalSection(&m_csLock); }
    inline void		LockThis()    { EnterCriticalSection(&m_csLock);      }    
    inline void		UnLockThis()  { LeaveCriticalSection(&m_csLock);      }
    inline void		DelLock()     { DeleteCriticalSection(&m_csLock);     }


private:
    PowerStatusType GetPowerStatus(PPOWER_BROADCAST pPowerInfo, int *piPercent);
    static DWORD WINAPI PowerThread(PVOID pArg);

    BOOL m_bExitThread;
    ULONG m_ulWaitTime;
    BOOL m_bRunning;
    CRITICAL_SECTION m_csLock;

    //This is for callback function.
    void (*m_pNotifyPower)(PowerStatusType powStatus, int iBatteryPercent);
};

#endif
